package com.se.domain.dto.wx;

import cn.hutool.json.JSONObject;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class WxUserAccessTokenDTO {
	private String accessToken;
	private Long expiresIn;
	private String refreshToken;
	private String openid;
	private String scope;
	private Byte isSnapshotUser;
	private String unionId;
	private Long expiresTime;
	
	public WxUserAccessTokenDTO(JSONObject jsonObject) {
		this.accessToken = jsonObject.getStr("access_token");
		this.expiresIn = jsonObject.getLong("expires_in");
		this.refreshToken = jsonObject.getStr("refresh_token");
		this.openid = jsonObject.getStr("openid");
		this.scope = jsonObject.getStr("scope");
		this.isSnapshotUser = jsonObject.getByte("is_snapshotuser");
		this.unionId = jsonObject.getStr("unionid");
		//超时时间，expiresIn单位为秒，再减去一定误差时间，记为5分钟
		this.expiresTime = System.currentTimeMillis() + this.expiresIn * 1000 - 1000 * 60 * 5;
	}
}
